<?php

class Settings_model extends CI_Model
{
	// Protected or private properties
	protected $_table;
	
	// Constructor
	public function __construct()
	{
		parent::__construct();
		$this->_table = $this->config->item('database_tables');
	}

	// Public methods
	public function get_settings()
	{
		$this->db->select('name, value');
			
		$query = $this->db->get('site_setting');
			
		if ($query->num_rows() > 0)
		{
			$result = $query->result_array();

			foreach ($result as $row)
			{
				$result[$row['name']] = $row['value'];
			}
			
			return $result;
		}
	}
	
	public function update_settings()
	{
		//$offline_reason = ($this->input->post('enabled') == 0) ? $this->input->post('offline_reason') : '';

		$this->db->set('value', $this->input->post('site_name'));
		$this->db->where('name', 'site_name');
		$this->db->update('site_setting');
		
		$this->db->set('value', $this->input->post('site_description'));
		$this->db->where('name', 'site_description');
		$this->db->update('site_setting');
		
		$this->db->set('value', $this->input->post('admin_email'));
		$this->db->where('name', 'admin_email');
		$this->db->update('site_setting');
		
		$this->db->set('value', $this->input->post('banner_trai'));
		$this->db->where('name', 'banner_trai');
		$this->db->update('site_setting');
	}
}

/* End of file posts_model.php */
/* Location: ./application/modules/admin/models/posts_model.php */